package com.example.financechain.controller;


import com.alibaba.fastjson.JSON;
import com.example.financechain.Utils.JsonData;
import com.example.financechain.Utils.UserThreadLocal;
import com.example.financechain.domain.DTO.RoleDTO;
import com.example.financechain.domain.entity.Role;
import com.example.financechain.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author yy
 * @since 2023-04-13
 */
@RestController
@RequestMapping("private/role")
public class RoleController {

    @Autowired
    IRoleService roleService;

    /**
     * 认证用户
     * @param roledto
     * @return
     * @throws NoSuchAlgorithmException
     */
    @PostMapping ("/add")
    public JsonData addRole(@RequestBody RoleDTO roledto) throws NoSuchAlgorithmException {

      return   roleService.addRole(roledto);

    }

    /**
     * 查询当前登录用户的个人信息界面
     * @return
     */
    @GetMapping("queryRoleInfo")
    public JsonData queryRoleInfo(){

        Role role = UserThreadLocal.get();

        return JsonData.buildSuccess(role);

    }

    /**
     *查询认证用户
     * @return
     */
    @PostMapping("/query")
    public JsonData queryRole(){

        List<Role> rolelist = roleService.list();

        return JsonData.buildSuccess(rolelist);

    }


}
